var express = require('express');
var router = express.Router();
// var url = require('url')
// var querystring = require('querystring')

/* GET users listing. */
router.get('/', function (req, res, next) {

    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
    res.header("Content-Type", "application/json;charset=utf-8");

    var mysql = require('mysql')
    var connection = mysql.createConnection({
        host: 'localhost',
        port: '3306', //端口号
        user: 'root',
        password: '654321',
        database: 'db1'
    })
    connection.connect()
    connection.query("SELECT * FROM user", function (err, data) {
        if (err) {
            console.log("数据库访问出错", err);
        } else {
            res.send({
                code: 1,
                msg: "成功",
                data
            });
            // var query = url.parse(req.url).query
            // var queryObj = querystring.parse(query)
            // console.log(queryObj)
        }
    })
    connection.end()


});

module.exports = router;